/*
 * Stride has been included in Qmol with the kind permission of 
 * 
 * Dmitrij Frishman, PhD
 * Institute for Bioinformatics
 * GSF - Forschungszentrum f? Umwelt und Gesundheit, GmbH
 * Ingolst?ter Landstra? 1,
 * D-85764 Neuherberg, Germany
 *
 * Telephone: +49-89-3187-4201
 * Fax: +49-89-31873585
 * e-mail: d.frishman@gsf.de
 * WWW: http://mips.gsf.de/mips/staff/frishman/
 *
 * Stride copyright (see http://www.embl-heidelberg.de/stride/stride.html):
 *
 * All rights reserved, whether the whole  or  part  of  the  program  is
 * concerned.  Permission  to use, copy, and modify this software and its
 * documentation is granted for academic use, provided that:
 *
 *
 * i.	this copyright notice appears in all copies of the software  and
 *		related documentation;
 *
 * ii.  the reference given below (Frishman and  Argos,  1995)  must  be
 *		cited  in any publication of scientific results based in part or
 *		completely on the use of the program;
 *
 * iii.  bugs will be reported to the authors.
 *
 * The use of the  software  in  commercial  activities  is  not  allowed
 * without a prior written commercial license agreement.
 * 
 * WARNING: STRIDE is provided "as-is" and without warranty of any  kind,
 * express,  implied  or  otherwise,  including  without  limitation  any
 * warranty of merchantability or fitness for a particular purpose. In no
 * event will the authors be liable for any special, incidental, indirect
 * or consequential damages  of  any  kind,  or  any  damages  whatsoever
 * resulting  from loss of data or profits, whether or not advised of the
 * possibility of damage, and on any theory of liability, arising out  of
 * or in connection with the use or performance of this software.
 * 
 * For calculation of the residue solvent accessible area the program NSC
 * [3,4]   is   used   and   was  kindly  provided  by  Dr.  F.Eisenhaber
 * (EISENHABER@EMBL-HEIDELBERG.DE). Please direct to  him  all  questions
 * concerning specifically accessibility calculations.
 * 
 * Stride References:
 * 
 * 1.	Frishman,D & Argos,P. (1995) Knowledge-based secondary structure
 * 		assignment.  Proteins:  structure, function and genetics, 23,
 * 		566-579.
 * 
 * 2.	Kabsch,W. & Sander,C. (1983)  Dictionary  of  protein  secondary
 * 		structure:    pattern   recognition   of   hydrogen-bonded   and
 * 		geometrical features. Biopolymers, 22: 2577-2637.
 * 
 * 3.	Eisenhaber,  F.  and  Argos,  P.  (1993)  Improved  strategy  in
 * 		analytic  surface calculation for molecular systems: handling of
 * 		singularities and computational efficiency. J. comput. Chem. 14,
 * 		1272-1280.
 * 
 * 4.	Eisenhaber, F., Lijnzaad, P., Argos, P., Sander, C., and Scharf,
 * 		M.  (1995) The DOUBLE cubic lattice method: efficient approaches
 * 		to numerical integration of surface area and volume and  to  dot
 * 		surface contouring of molecular assemblies. J. comput. Chem. 16,
 * 		273-284.
 * 
 * 5.	Bernstein, F.C., Koetzle, T.F.,  Williams,  G.J.,  Meyer,  E.F.,
 * 		Brice,  M.D.,  Rodgers,  J.R., Kennard, O., Shimanouchi, T., and
 * 		Tasumi, M.  (1977)  The  protein  data  bank:  a  computer-based
 * 		archival  file for macromolecular structures. J. Mol. Biol. 112,
 * 		535-542.
 * 
 * 6.	Kraulis, P.J.  (1991)  MOLSCRIPT:  a  program  to  produce  both
 * 		detailed  and  schematic  plots  of protein structures. J. Appl.
 * 		Cryst. 24, 946-950.
 * 
 * 7.	Pearson, W.R. (1990) Rapid  and  sensitive  sequence  comparison
 * 		with FASTP and FASTA. Methods. Enzymol. 183, 63-98.
 * 
 */
STRIDE_BOOL ChInStr(char *String, char Char);
STRIDE_BOOL ExistsSecStr(CHAIN **Chain, INT32 NChain);
STRIDE_BOOL ExistSSBond(CHAIN **Chain,INT32 NChain,INT32 Cn1,INT32 Cn2,char *Res1,char *Res2);
STRIDE_BOOL IsHydrogen(char *AtomName) ;
STRIDE_BOOL Specified(char **List, INT32 ListLength, char Option);

FILE *efopen(char *file, char *mode, char *progname);

char **AllocAsn(CHAIN **Chain, INT32 NChain);
char **CharMatrix(INT32 M, INT32 N);
char *OneToThree(char One);
char SpaceToDash(char Id);
char *Tim(void);
char ThreeToOne(char *Three);
char *tolostr(char *InputString);
char *Translate(char Code);

DOUBLE GetAtomRadius(char *AtomType);

FLOAT Ang(FLOAT *Coord1, FLOAT *Coord2, FLOAT *Coord3);
FLOAT **DefaultHelixMap(COMMAND *Cmd);
FLOAT **DefaultSheetMap(COMMAND *Cmd);
FLOAT Dist(FLOAT *Coord1, FLOAT *Coord2);
FLOAT ***FloatCube(INT32 M, INT32 N, INT32 K);
FLOAT **FloatMatrix(INT32 M, INT32 N);
FLOAT PercentCorrect(char *TestAsn, char *KnownAsn, INT32 Length);
FLOAT SecStrContent(CHAIN *Chain, INT32 *HelAlp, INT32 *HelPI, INT32 *Hel310, INT32 *Sheet, INT32 *Turn);
FLOAT Torsion(FLOAT *Coord1, FLOAT *Coord2, FLOAT *Coord3, FLOAT *Coord4);
FLOAT VectorProduct(FLOAT *Vector1, FLOAT *Vector2, FLOAT *Product);
FLOAT factrl(INT32 n);

INT32 AssessCorr(QUALITY *Qual);
INT32 AssessPerc(QUALITY *Qual);
INT32 Boundaries(char *Asn, INT32 L, char SecondStr, INT32 (*Bound)[2]);
INT32 CheckAtom(char *At);
INT32 CheckChain(CHAIN *Chain, COMMAND *Cmd);
INT32 CheckRes(char *Res);
INT32 CompareElements(char *Asn1, char *Asn2, char *Asn3, INT32 Length, 
		   char SecStrType, INT32 *Better, INT32 *Worse);
INT32 CompPdbDssp(CHAIN *Chain, DSSP *Dssp);
INT32 CollectOptions(char **List, INT32 ListLength, INT32 Stream, INT32 *Options);
INT32 DefineAcceptor(CHAIN *Chain, ACCEPTOR **Acc, INT32 *ac, INT32 Res, enum HYBRID Hybrid,  
		   enum GROUP Group, FLOAT HB_Radius, INT32 N);
INT32 DefineDnr(CHAIN *Chain, DONOR **Dnr, INT32 *dc, INT32 Res, enum HYBRID Hybrid, 
	      enum GROUP Group,  FLOAT HB_Radius, INT32 N);
INT32 Delete(char *String, char From);
INT32 Difference(char *TestAsn, char *KnownAsn, INT32 Length, char SecStrType, QUALITY *Qual);
INT32 escape(INT32 RetVal, char *format, ... );
INT32 FindAcc(CHAIN *Chain, ACCEPTOR **Acc, INT32 *NAcc, COMMAND *Cmd);

/*
 * The function FindAtom is already defined by windows
 */
INT32 stride_FindAtom(CHAIN *Chain, INT32 ResNumb, char *Atom, INT32 *AtNumb);

INT32 FindBnd(HBOND **HBond, RESIDUE *Res1, RESIDUE *Res2);
INT32 FindChain(CHAIN **Chain, INT32 NChain, char ChainId);
INT32 FindDnr(CHAIN *Chain, DONOR **Dnr, INT32 *NDnr, COMMAND *Cmd);
INT32 FindHydrogenBonds(CHAIN **Chain, INT32 NChain, HBOND **HBond, COMMAND *Cmd,
					  DONOR ***Dnr, ACCEPTOR ***Acc);
INT32 FindPolInt(HBOND **HBond, RESIDUE *Res1, RESIDUE *Res2);
INT32 FullElement(char *Asn1, char *Asn2, char *Asn3, INT32 Length, char SecStrType, 
		       INT32 ElemLength, char EditChar, INT32 *YYN, INT32 *NYY, INT32 *YNN, INT32 *NNY);
INT32 GetPdbChain(CHAIN **Chain, FILE *Db, INT32 Start);
INT32 ***IntCube(INT32 M, INT32 N, INT32 K);
INT32 **IntMatrix(INT32 M, INT32 N);
INT32 Link(HBOND **HBond, CHAIN **Chain, INT32 Cn1, INT32 Cn2, RESIDUE *Res1_1, 
	 RESIDUE *Res1_2, RESIDUE *Res2_2, RESIDUE *Res2_1, RESIDUE *CRes1, RESIDUE *CRes2,
	 FLOAT **PhiPsiMap, STRIDE_PATTERN **Pattern, INT32 *NumPat, char *Text, FLOAT Treshold, 
	 COMMAND *Cmd, INT32 Test);
INT32 MakeEnds(INT32 *Beg1, INT32 ResBeg1, INT32 NeiBeg1, char *Beg1Cn, char ResBeg1Cn, 
		    INT32 *End1, INT32 ResEnd1, INT32 NeiEnd1, char ResEnd1Cn, INT32 *Beg2, 
		    INT32 ResBeg2, INT32 NeiBeg2, char *Beg2Cn, char ResBeg2Cn, INT32 *End2, 
		    INT32 ResEnd2, INT32 NeiEnd2, char ResEnd2Cn, STRIDE_PATTERN **Pat, INT32 NPat);
INT32 MolScript(CHAIN **Chain, INT32 NChain, COMMAND *Cmd);
INT32 Near(INT32 Res1, INT32 Res2, INT32 Res3, INT32 Res4, INT32 Res5, INT32 Res6, INT32 Res7, INT32 Res8,
	 char Cn1, char Cn2, char Cn3, char Cn4, INT32 *DistBest, INT32 *DistWorst);
INT32 NearPar(INT32 Res1, INT32 Res2, INT32 Res3, INT32 Res4, INT32 Res5, INT32 Res6, INT32 Res7, INT32 Res8,
	 char Cn1, char Cn2, char Cn3, char Cn4, INT32 *DistBest, INT32 *DistWorst);
INT32 NoDoubleHBond(HBOND **HBond, INT32 NHBond);
INT32 OutSeq(CHAIN **Chain, INT32 NChain, COMMAND *Cmd);
INT32 Parse(char **List, INT32 ListLength, char *Option);
INT32 PdbN2SeqN(CHAIN *Chain, char *PdbN, INT32 *SeqN);
INT32 PlaceHydrogens(CHAIN *Chain);
INT32 Presnell(char *Asn1, INT32 L1, char *Asn2, INT32 L2, char SecStr, FLOAT Threshold, 
	       FLOAT *Q2, FLOAT *O);
INT32 Process_ATOM(BUFFER Buffer, CHAIN **Chain, INT32 *ChainNumber, 
		 STRIDE_BOOL *First_ATOM, COMMAND *Cmd);
INT32 Process_COMPND(BUFFER Buffer, enum METHOD *Method);
INT32 Process_ENDMDL(BUFFER Buffer, CHAIN **Chain, INT32 *ChainNumber);
INT32 Process_EXPDTA(BUFFER Buffer, enum METHOD *Method);
INT32 Process_HELIX(BUFFER Buffer, CHAIN **Chain, INT32 *ChainNumber, COMMAND *Cmd);
INT32 Process_JRNL(BUFFER Buffer, STRIDE_BOOL *Published);
INT32 Process_MODEL(enum METHOD *Method);
INT32 Process_REMARK(BUFFER Buffer, enum METHOD *Method, FLOAT *Resolution, STRIDE_BOOL *DsspAssigned);
INT32 Process_SHEET(BUFFER Buffer, CHAIN **Chain, INT32 *ChainNumber, COMMAND *Cmd);
INT32 Process_SSBOND(BUFFER Buffer, CHAIN **Chain, INT32 *ChainNumber, COMMAND *Cmd);
INT32 Process_TER(BUFFER Buffer, CHAIN **Chain, INT32 *ChainNumber);
INT32 Process_TURN(BUFFER Buffer, CHAIN **Chain, INT32 *ChainNumber, COMMAND *Cmd);
INT32 ReadDSSP(CHAIN **Chain, DSSP **Dssp, COMMAND *Cmd);
INT32 ReadPDBFile(CHAIN **Chain, INT32 *NChain, COMMAND *Cmd);
INT32 ReadPhiPsiMap(char *MapFile, FLOAT ***PhiPsiMap, COMMAND *Cmd);
INT32 Replace(char *String, char From, char To);
INT32 ResInSecondStr(INT32 ResNumb, INT32 (*Bound)[2], INT32 N, INT32 *StrNumb);
INT32 RightSide(INT32 LnkA, INT32 LnkD, INT32 I1A, INT32 I1D, INT32 I2A, INT32 I2D );
INT32 RightSide2(INT32 L_A1, INT32 L_D1, INT32 LnkD, INT32 LnkA, INT32 I1A, INT32 I1D, INT32 I2A, INT32 I2D);
INT32 RightSidePar(INT32 LnkA, INT32 LnkD, INT32 I1A, INT32 I1D, INT32 I2A, INT32 I2D );
INT32 SplitString(char *Buffer, char **Fields, INT32 MaxField);
INT32 SSBond(CHAIN **Chain, INT32 NChain);
INT32 TorsBracket(FLOAT Torsion, FLOAT Min, FLOAT Max);
INT32 TurnCondition(FLOAT Phi2,FLOAT Phi2S,FLOAT Psi2,FLOAT Psi2S,
		  FLOAT Phi3,FLOAT Phi3S,FLOAT Psi3,FLOAT Psi3S,
		  FLOAT Range1,FLOAT Range2);
INT32 Uniq(char **List, INT32 ListLength);
void Alias(INT32 *D1,INT32 *A1,INT32 *D2,INT32 *A2,char *D1Cn,char *A1Cn,char *D2Cn,char *A2Cn,
	  STRIDE_PATTERN *Pat);
void AllocChain(CHAIN **Chain);
void Area(CHAIN **Chain, INT32 NChain, COMMAND *Cmd);
void BackboneAngles(CHAIN **Chain, INT32 NChain);
void BetaTurn(CHAIN **Chain, INT32 Cn);
void Bridge(char *Asn1, char *Asn2, CHAIN **Chain, INT32 Cn1, INT32 Cn2, STRIDE_PATTERN **Pat, INT32 NPat);
void *ckalloc(size_t bytes);
void CorrectAsn(char *Asn, INT32 Length, char SecStrType, char EditChar, INT32 MaxLength);
void CorrectAsnDouble(char *Asn1, char *Asn2, char *KnownAsn, INT32 Length, 
		      char SecStrType, char EditChar);
void DeallocAcc(DONOR **Acc, INT32 AccNumber);
void DeallocDnr(DONOR **Dnr, INT32 DonNumber);
void DefaultCmd(COMMAND *Cmd, INT32 max_num_res);
void die(char *format, ... );
void DiscrPhiPsi(CHAIN **Chain, INT32 NChain, COMMAND *Cmd);
void DistMatrix(CHAIN *Chain);
void DSSP_Energy(FLOAT *Dummy, FLOAT *C, FLOAT *O, FLOAT *H, FLOAT *N, COMMAND *Cmd, 
				 HBOND *HBond);
void GRID_Energy(FLOAT *CA2, FLOAT *C, FLOAT *O, FLOAT *H, FLOAT *N, COMMAND *Cmd, 
				 HBOND *HBond);
void ExcludeObvious(char *Asn1, char *Asn2, char *KnownAsn, INT32 Length);
void ExtractAsn(CHAIN **Chain, INT32 Cn, char *Asn);
void ExtractPdbAsn(CHAIN **Chain, INT32 Cn, char *Asn);
void ExtractDsspAsn(CHAIN **Chain, INT32 Cn, char *Asn);
void FillAsnAntiPar(char *Asn1, char *Asn2, CHAIN **Chain, INT32 Cn1, INT32 Cn2, 
		    STRIDE_PATTERN **Pat, INT32 NPat, COMMAND *Cmd);
void FillAsnPar(char *Asn1, char *Asn2, CHAIN **Chain, INT32 Cn1, INT32 Cn2, 
		STRIDE_PATTERN **Pat, INT32 NPat, COMMAND *Cmd);
void FilterAntiPar(STRIDE_PATTERN **Pat, INT32 NPat);
void FilterPar(STRIDE_PATTERN **Pat, INT32 NPat);
void FreeCharMatrix(char **Matrix, INT32 M);
void FreeFloatMatrix(FLOAT **Matrix, INT32 M);
void FreeIntMatrix(INT32 **Matrix, INT32 M);
void GammaTurn(CHAIN **Chain, INT32 Cn, HBOND **HBond);
void GetFileNameFromPath(char *Path, char *FileName);
void GetDsspAsn(CHAIN **Chain, INT32 NChain, COMMAND *Cmd);
void GetPdbAsn(CHAIN **Chain, INT32 NChain);
void Glue(char *String1, char *String2, FILE *Out);
void Helix(CHAIN **Chain, INT32 Cn, HBOND **HBond, COMMAND *Cmd, FLOAT **PhiPsiMap);
void HBondToBins(HBOND **HBond, INT32 NHBond, COMMAND *Cmd);
void InitAsn(CHAIN **Chain, INT32 NChain);
void StrideInitChain(CHAIN **Chain, COMMAND *Cmd);
void InsertFirst(DSSP *Dssp, CHAIN *Chain);
void InsertLast(DSSP *Dssp, CHAIN *Chain);
void JoinNeighb(STRIDE_PATTERN **Nei, STRIDE_PATTERN *Pat, INT32 *MinDB2, INT32 DB, INT32 *MinDW2, INT32 DW);
void JoinNeighbours(INT32 *Lnk1A, INT32 Res1, INT32 *Lnk1D, INT32 Res2, STRIDE_PATTERN **Nei, 
		    STRIDE_PATTERN *Pat, INT32 *MinDB1, INT32 DB, INT32 *MinDW1, INT32 DW, INT32 *Min, INT32 j);
void Measure(CHAIN **Chain, INT32 NChain, INT32 El, COMMAND *Cmd, FILE *Out);
void MergePatternsPar(STRIDE_PATTERN **Pat, INT32 NPat);
void MergePatternsAntiPar(STRIDE_PATTERN **Pat, INT32 NPat);
INT32 NotValid(CHAIN *Chain, char *Message);
void OMEGA(CHAIN *Chain, INT32 Res);
void PHI(CHAIN *Chain, INT32 Res);
void Place123_X(FLOAT *Coord1, FLOAT *Coord2, FLOAT *Coord3, FLOAT Dist3X, FLOAT Ang23X,  
		FLOAT *CoordX);
void PrepareBuffer(BUFFER Bf, CHAIN **Chain);
void PrintHydrBond(char *Text, HBOND *HBond);
void PrintPatterns(STRIDE_PATTERN **Pat, INT32 NPat, CHAIN **Chain, INT32 Cn1, INT32 Cn2);
void Project4_123(FLOAT *Coord1, FLOAT *Coord2, FLOAT *Coord3, FLOAT *Coord4,  
		  FLOAT *Coord_Proj4_123);
void PSI(CHAIN *Chain, INT32 Res);
void Report(CHAIN **Chain, INT32 NChain, HBOND **HBond, COMMAND *Cmd);
void ReportDetailed(CHAIN **Chain, INT32 NChain, FILE *Out, COMMAND *Cmd);
void ReportGeneral(CHAIN **Chain, FILE *Out);
void ReportHydrBonds(CHAIN **Chain, INT32 NChain, HBOND **HBond, 
			    FILE *Out, COMMAND *Cmd);
void ReportShort(CHAIN **Chain, INT32 NChain, FILE *Out, COMMAND *Cmd);
void ReportSSBonds(CHAIN **Chain, FILE *Out);
void ReportSummary(CHAIN **Chain, INT32 NChain, FILE *Out, COMMAND *Cmd);
void ReportTurnTypes(CHAIN **Chain, INT32 NChain, FILE *Out, COMMAND *Cmd);
void Sheet(CHAIN **Chain, INT32 Cn1, INT32 Cn2, HBOND **HBond, COMMAND *Cmd, FLOAT **PhiPsiMap);
void StringSort(char **Strings, INT32 left, INT32 right, INT32 StrLen);
void StripPathFromLastExtention(char *Path, char *StrippedPath);





